import { Controller, Inject, Get, Query, Body, Post, Put, Param, Del } from '@midwayjs/core';
import { NoticeService } from "@service/system/notice.service";
import { ListNoticeDTO, CreateNoticeDTO, UpdateNoticeDTO } from "@dto/system/notice.dto";
import { Auth } from "@decorator/auth.decorator";
import { BusinessType, Log } from "@decorator/log.decorator";

@Controller('/system/notice')
export class PostController {
  @Inject()
  noticeService: NoticeService;

  // 获取列表
  @Auth('system:notice:list')
  @Get('/list')
  async list(@Query() queryParams: ListNoticeDTO) {
    return await this.noticeService.list(queryParams);
  }

  // 新增
  @Auth('system:notice:add')
  @Log({ title: '通知公告', businessType: BusinessType.ADD })
  @Post('/')
  async create(@Body() notice: CreateNoticeDTO) {
    return await this.noticeService.create(notice);
  }

  // 删除
  @Auth('system:notice:remove')
  @Log({ title: '通知公告', businessType: BusinessType.REMOVE })
  @Del('/:noticeId')
  async delete(@Param('noticeId') noticeId: string) {
    return await this.noticeService.delete(noticeId);
  }

  // 修改
  @Auth('system:notice:edit')
  @Log({ title: '通知公告', businessType: BusinessType.EDIT })
  @Put('/')
  async update(@Body() notice: UpdateNoticeDTO) {
    return await this.noticeService.update(notice);
  }

  // 获取详情
  @Auth('system:notice:query')
  @Get('/:noticeId')
  async get(@Param('noticeId') noticeId: number) {
    return await this.noticeService.detail(noticeId);
  }

}
